<template>
    <div>
        <h1>添加课程</h1>
        <p>课程名：<input type="text" v-model="course_name"></p>
        <p>参课人数：<input type="text" v-model="course_number"></p>
        <p>课程封面：<input type="file" id="img"></p>
        <p>课程老师：<input type="text" v-model="user"></p>
        <p><button @click="add">添加</button></p>
    </div>
</template>

<script>
import axios from 'axios'
export default {
    data() {
        return {
            base_url:'http://127.0.0.1:8000',
            course_name:'',
            course_number:'',
            user:sessionStorage.getItem('user_id')
        }
    },
    methods: {
        add() {
            let img=document.getElementById('img').files[0]
            let fdata=new FormData()
            fdata.append('course_name',this.course_name)
            fdata.append('course_number',this.course_number)
            fdata.append('user',this.user)
            fdata.append('course_img',img)
            axios({
                url:this.base_url+'/app02/course_api/',
                method:'post',
                data:fdata
            }).then(resp=>{
                console.log(resp.data)
            })
        }
    },
    created() {

    }
}
</script>

<style scoped>

</style>
